import { ISequence } from "../../interface/composite/ISequence";
import { BaseComposite } from "../../base/BaseComposite";
import { IBehaviour } from "../../interface/IBehaviour";
import { EStatus } from "../../common/EnumType";
import { myclass } from "../../../../engine/decorators";

@myclass("SelectorImpl")
export class SelectorImpl extends BaseComposite implements ISequence {
    public onUpdate(): EStatus {
        let iBehaviours: Array<IBehaviour> = this.getChildren();
        if (iBehaviours.length != 0) {
            for (let i = 0; i < iBehaviours.length; i++) {
                let iBehaviour = iBehaviours[i];
                let s = iBehaviour.tick();
                if (s != EStatus.Failure) {
                    return s;
                }
            }
            return EStatus.Failure;
        }
        return EStatus.Invalid;
    }
}